package com.fenghuajueli.idiomppp.ui.guessidiom;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.fenghuajueli.idiomppp.R;

public class GuessBackDialog extends Dialog {
    private TextView tvConfirm,tvCancel,tvTitle;
    private ImageView ivClose;
    private Context context;

    public GuessBackDialog(Context context) {
        super(context, R.style.ResultDialog);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_guess_back);
        setCanceledOnTouchOutside(false);

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);

        initView();
        initListener();
    }

    private void initView() {
        tvCancel = findViewById(R.id.tv_cancel);
        tvConfirm = findViewById(R.id.tv_confirm);
        tvTitle = findViewById(R.id.tv_title);
        ivClose = findViewById(R.id.iv_close);

        Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/baotuxiaobaiti.ttf");
        tvTitle.setTypeface(tf);
    }

    private void initListener() {
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)context).finish();
            }
        });
    }

}
